package com.cloud.client;

import okhttp3.Interceptor;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

/**
 *  监听下载进度
 *
 */
public class ProgressResponseInterceptor implements Interceptor{
    private final ProgressListener progressListener;

    public ProgressResponseInterceptor(ProgressListener progressListener) {
        this.progressListener = progressListener;
    }

    @NotNull
    @Override
    public Response intercept(Interceptor.Chain chain) throws IOException {
        Response responseResponse = chain.proceed(chain.request());
        return responseResponse.newBuilder()
                .body(new DownloadResponseBody(responseResponse, progressListener))
                .build();
    }
}
